﻿using System;
using System.Collections.Generic;
using System.Text;
using DreamShield.Deployment.Installers.DreamWorker.Workers;
using DreamShield.Deployment.Installers.DreamWorker;
using DreamShield.Deployment.Wizards.Workflow;
using DreamShield.Deployment.Package;
using DreamShield.Deployment.Listers;
using DreamShield.IO.Utils.VFS;
using System.IO;

namespace DreamShield.Deployment.Miles.IO
{
    /// <summary>
    /// Plugin qui permet d'exécuter les opérations de l'installeur sur des fichiers.
    /// </summary>
    public class CustomFilesHandlerPlugin : BaseMilesPlugin
    {
        /// <summary>
        /// Initialise une nouvelle instance de l'intercepteur d'action sur les fichiers
        /// </summary>
        /// <param name="server"></param>
        public CustomFilesHandlerPlugin(MilesRootServer server)
            : base(server)
        {
            ImplNativeHandler = new NativeHandler(this);

            _NativePluginImplementation = ImplNativeHandler;
            _NativePluginType = FileWorker.PluginsGuid;
        }

        #region Liaison avec DreamShield

        /// <summary>
        /// Infrastucture de communication avec le runtime
        /// </summary>
        protected virtual NativeHandler ImplNativeHandler { get; set; }

        /// <summary>
        /// Handler natif utilisé pour la communication avec DreamShield
        /// </summary>
        protected class NativeHandler : BaseFileWorker_Plugin
        {
            /// <summary>
            /// Objet vers lequel rediriger les appels
            /// </summary>
            public virtual CustomFilesHandlerPlugin RawTarget { get; protected set; }

            /// <summary>
            /// Crée une nouvelle instance de l'handler natif
            /// </summary>
            /// <param name="target"></param>
            public NativeHandler(CustomFilesHandlerPlugin target)
            {
                RawTarget = target;
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="target"></param>
            /// <param name="ActionId"></param>
            /// <param name="componentFlow"></param>
            /// <param name="component"></param>
            /// <param name="file_path"></param>
            public override void Action_ExecuteFile_Begin(DreamWorkerEngine target, WorkerActionId ActionId, WorkflowSequencer componentFlow, PackageComponent component, string file_path)
            {
                RawTarget.ExecuteFile_Begin(target, ActionId, component, file_path);
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="target"></param>
            /// <param name="descriptor"></param>
            /// <param name="runtime_file"></param>
            /// <param name="target_path"></param>
            /// <param name="actionName"></param>
            /// <param name="realAction"></param>
            /// <param name="execute"></param>
            public override void Action_ExecuteFile_Effective_Begin(DreamWorkerEngine target, ListersComponentFilesDescriptors descriptor, IVFSFile runtime_file, string target_path, string actionName, ref string realAction, ref bool execute)
            {
                RawTarget.ExecuteFile_Effective_Begin(target, target_path, actionName, ref realAction, ref execute);
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="target"></param>
            /// <param name="descriptor"></param>
            /// <param name="runtime_file"></param>
            /// <param name="target_path"></param>
            /// <param name="actionName"></param>
            /// <param name="realAction"></param>
            public override void Action_ExecuteFile_Effective_End(DreamWorkerEngine target, ListersComponentFilesDescriptors descriptor, IVFSFile runtime_file, string target_path, string actionName, string realAction)
            {
                RawTarget.ExecuteFile_Effective_End(target, target_path, actionName, realAction);
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="target"></param>
            /// <param name="ActionId"></param>
            /// <param name="componentFlow"></param>
            /// <param name="component"></param>
            /// <param name="file_path"></param>
            public override void Action_ExecuteFile_End(DreamWorkerEngine target, WorkerActionId ActionId, WorkflowSequencer componentFlow, PackageComponent component, string file_path)
            {
                RawTarget.ExecuteFile_End(target, ActionId, component, file_path);
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="target"></param>
            /// <param name="ActionId"></param>
            /// <param name="componentFlow"></param>
            /// <param name="component"></param>
            public override void AfterGenerate_ExecuteComponent(DreamWorkerEngine target, WorkerActionId ActionId, WorkflowSequencer componentFlow, PackageComponent component)
            {
                RawTarget.AfterGenerate_ExecuteComponent(target, ActionId, component);
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="target"></param>
            /// <param name="ActionId"></param>
            /// <param name="packageFlow"></param>
            public override void AfterGenerate_ExecuteInstallation_AfterComponents(DreamWorkerEngine target, WorkerActionId ActionId, WorkflowSequencer packageFlow)
            {
                RawTarget.AfterGenerate_ExecuteInstallation_AfterComponents(target, ActionId);
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="target"></param>
            /// <param name="ActionId"></param>
            /// <param name="packageFlow"></param>
            public override void AfterGenerate_ExecuteInstallation_BeforeComponents(DreamWorkerEngine target, WorkerActionId ActionId, WorkflowSequencer packageFlow)
            {
                RawTarget.AfterGenerate_ExecuteInstallation_BeforeComponents(target, ActionId);
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="target"></param>
            /// <param name="packageFlow"></param>
            public override void AfterGenerate_RollBack(DreamWorkerEngine target, WorkflowSequencer packageFlow)
            {
                RawTarget.AfterGenerate_RollBack(target);
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="target"></param>
            /// <param name="ActionId"></param>
            /// <param name="componentFlow"></param>
            /// <param name="component"></param>
            public override void BeforeGenerate_ExecuteComponent(DreamWorkerEngine target, WorkerActionId ActionId, WorkflowSequencer componentFlow, PackageComponent component)
            {
                RawTarget.BeforeGenerate_ExecuteComponent(target, ActionId, component);
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="target"></param>
            /// <param name="ActionId"></param>
            /// <param name="packageFlow"></param>
            public override void BeforeGenerate_ExecuteInstallation_AfterComponents(DreamWorkerEngine target, WorkerActionId ActionId, WorkflowSequencer packageFlow)
            {
                RawTarget.BeforeGenerate_ExecuteInstallation_AfterComponents(target, ActionId);
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="target"></param>
            /// <param name="ActionId"></param>
            /// <param name="packageFlow"></param>
            public override void BeforeGenerate_ExecuteInstallation_BeforeComponents(DreamWorkerEngine target, WorkerActionId ActionId, WorkflowSequencer packageFlow)
            {
                RawTarget.BeforeGenerate_ExecuteInstallation_BeforeComponents(target, ActionId);
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="target"></param>
            /// <param name="packageFlow"></param>
            public override void BeforeGenerate_RollBack(DreamWorkerEngine target, WorkflowSequencer packageFlow)
            {
                RawTarget.BeforeGenerate_RollBack(target);
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="descriptor"></param>
            /// <param name="runtime_file"></param>
            /// <param name="rollBackRecords"></param>
            /// <param name="file_info"></param>
            /// <param name="file_name"></param>
            public override void IOWorker_CreateFile(ListersComponentFilesDescriptors descriptor, IVFSFile runtime_file, DreamShield.Data.IDataEntry rollBackRecords, System.IO.FileInfo file_info, ref string file_name)
            {
                RawTarget.IOWorker_CreateFile(file_info, ref file_name);
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="descriptor"></param>
            /// <param name="runtime_file"></param>
            /// <param name="rollBackRecords"></param>
            /// <param name="file_info"></param>
            /// <param name="file_name"></param>
            public override void IOWorker_CreateFile_Done(ListersComponentFilesDescriptors descriptor, IVFSFile runtime_file, DreamShield.Data.IDataEntry rollBackRecords, System.IO.FileInfo file_info, ref string file_name)
            {
                RawTarget.IOWorker_CreateFile_Done(file_info, ref file_name);
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="rollBackRecords"></param>
            /// <param name="file_info"></param>
            public override void IOWorker_DeleteFile(DreamShield.Data.IDataEntry rollBackRecords, System.IO.FileInfo file_info)
            {
                RawTarget.IOWorker_DeleteFile(file_info);
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="rollBackRecords"></param>
            /// <param name="file_info"></param>
            public override void IOWorker_DeleteFile_Done(DreamShield.Data.IDataEntry rollBackRecords, System.IO.FileInfo file_info)
            {
                RawTarget.IOWorker_DeleteFile_Done(file_info);
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="rollBackRecords"></param>
            /// <param name="file_info"></param>
            public override void IOWorker_UninstallFile(DreamShield.Data.IDataEntry rollBackRecords, System.IO.FileInfo file_info)
            {
                RawTarget.IOWorker_UninstallFile(file_info);
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="rollBackRecords"></param>
            /// <param name="file_info"></param>
            public override void IOWorker_UninstallFile_Done(DreamShield.Data.IDataEntry rollBackRecords, System.IO.FileInfo file_info)
            {
                RawTarget.IOWorker_UninstallFile_Done(file_info);
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="rollBack"></param>
            /// <param name="file_info"></param>
            public override void RestoreFileRollBack(DreamShield.Data.IDataSequentialChild rollBack, System.IO.FileInfo file_info)
            {
                RawTarget.RestoreFileRollBack(file_info);
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="rollBack"></param>
            /// <param name="file_info"></param>
            public override void RestoreFileRollBack_Done(DreamShield.Data.IDataSequentialChild rollBack, System.IO.FileInfo file_info)
            {
                RawTarget.RestoreFileRollBack_Done(file_info);
            }

            /// <summary>
            /// Infrastructure de communication
            /// </summary>
            /// <param name="file"></param>
            /// <param name="target_path"></param>
            public override void Utils_GetFileTargetPath(IVFSFile file, ref string target_path)
            {
                RawTarget.Utils_GetFileTargetPath(ref target_path);
            }
        }

        #endregion

        /// <summary>
        /// Appelé avant l'exécution d'une action sur un fichier
        /// </summary>
        /// <param name="target">Engine actuelle</param>
        /// <param name="ActionId">ID de l'action</param>
        /// <param name="component">Composant actuel</param>
        /// <param name="file_path">Chemin du fichier</param>
        public delegate void ExecuteFile_Begin_Handler(DreamWorkerEngine target, WorkerActionId ActionId, PackageComponent component, string file_path);

        /// <summary>
        /// Appelé avant l'exécution d'une action sur un fichier
        /// </summary>
        public event ExecuteFile_Begin_Handler OnExecuteFile_Begin;

        /// <summary>
        /// Provoque l'évènement OnExecuteFile_Begin
        /// </summary>
        /// <param name="target"></param>
        /// <param name="ActionId"></param>
        /// <param name="component"></param>
        /// <param name="file_path"></param>
        protected virtual void ExecuteFile_Begin(DreamWorkerEngine target, WorkerActionId ActionId, PackageComponent component, string file_path)
        {
            if (OnExecuteFile_Begin != null)
                OnExecuteFile_Begin(target, ActionId, component, file_path);
        }

        /// <summary>
        /// Appelé avant l'exécution effective d'une action sur un fichier
        /// </summary>
        /// <param name="target">Engine actuelle</param>
        /// <param name="target_path">Chemin de destination du fichier</param>
        /// <param name="actionName">Nom de l'action</param>
        /// <param name="realAction">Action effective qui sera exécutée par l'installeur sur ce fichier</param>
        /// <param name="execute">Indique si l'action doit être exécuté</param>
        /// <remarks>L'action peut être ignorée en affectant à execute la valeur false</remarks>
        public delegate void ExecuteFile_Effective_Begin_Handler(DreamWorkerEngine target, string target_path, string actionName, ref string realAction, ref bool execute);

        /// <summary>
        /// Appelé avant l'exécution effective d'une action sur un fichier
        /// </summary>
        public event ExecuteFile_Effective_Begin_Handler OnExecuteFile_Effective_Begin;

        /// <summary>
        /// Provoque l'évènement OnExecuteFile_Effective_Begin
        /// </summary>
        /// <param name="target"></param>
        /// <param name="target_path"></param>
        /// <param name="actionName"></param>
        /// <param name="realAction"></param>
        /// <param name="execute"></param>
        protected virtual void ExecuteFile_Effective_Begin(DreamWorkerEngine target, string target_path, string actionName, ref string realAction, ref bool execute)
        {
            if (OnExecuteFile_Effective_Begin != null)
                OnExecuteFile_Effective_Begin(target, target_path, actionName, ref realAction, ref execute);
        }

        /// <summary>
        /// Appelé après l'exécution effective d'une action sur un fichier
        /// </summary>
        /// <param name="target">Engine actuelle</param>
        /// <param name="target_path">Chemin de destination du fichier</param>
        /// <param name="actionName">Nom de l'action</param>
        /// <param name="realAction">Action effective qui sera exécutée par l'installeur sur ce fichier</param>
        public delegate void ExecuteFile_Effective_End_Handler(DreamWorkerEngine target, string target_path, string actionName, string realAction);

        /// <summary>
        /// Appelé après l'exécution effective d'une action sur un fichier
        /// </summary>
        public event ExecuteFile_Effective_End_Handler OnExecuteFile_Effective_End;

        /// <summary>
        /// Provoque l'évènement OnExecuteFile_Effective_End
        /// </summary>
        /// <param name="target"></param>
        /// <param name="target_path"></param>
        /// <param name="actionName"></param>
        /// <param name="realAction"></param>
        protected virtual void ExecuteFile_Effective_End(DreamWorkerEngine target, string target_path, string actionName, string realAction)
        {
            if (OnExecuteFile_Effective_End != null)
                OnExecuteFile_Effective_End(target, target_path, actionName, realAction);
        }

        /// <summary>
        /// Appelé après l'exécution d'une action sur un fichier
        /// </summary>
        /// <param name="target">Engine actuelle</param>
        /// <param name="ActionId">ID de l'action</param>
        /// <param name="component">Composant actuel</param>
        /// <param name="file_path">Chemin du fichier</param>
        public delegate void ExecuteFile_End_Handler(DreamWorkerEngine target, WorkerActionId ActionId, PackageComponent component, string file_path);

        /// <summary>
        /// Appelé après l'exécution d'une action sur un fichier
        /// </summary>
        public event ExecuteFile_End_Handler OnExecuteFile_End;

        /// <summary>
        /// Provoque l'évènement OnExecuteFile_End
        /// </summary>
        /// <param name="target"></param>
        /// <param name="ActionId"></param>
        /// <param name="component"></param>
        /// <param name="file_path"></param>
        protected virtual void ExecuteFile_End(DreamWorkerEngine target, WorkerActionId ActionId, PackageComponent component, string file_path)
        {
            if (OnExecuteFile_End != null)
                OnExecuteFile_End(target, ActionId, component, file_path);
        }

        /// <summary>
        /// Appelé après que le Worker génère les actions pour un composant
        /// </summary>
        /// <param name="target">Engine de destination</param>
        /// <param name="ActionId">Id de l'action</param>
        /// <param name="component">Composant actuel</param>
        public delegate void AfterGenerate_ExecuteComponent_Handler(DreamWorkerEngine target, WorkerActionId ActionId, PackageComponent component);

        /// <summary>
        /// Appelé après que le Worker génère les actions pour un composant
        /// </summary>
        public event AfterGenerate_ExecuteComponent_Handler OnAfterGenerate_ExecuteComponent;

        /// <summary>
        /// Provoque l'évènement OnAfterGenerate_ExecuteComponent
        /// </summary>
        /// <param name="target"></param>
        /// <param name="ActionId"></param>
        /// <param name="component"></param>
        protected virtual void AfterGenerate_ExecuteComponent(DreamWorkerEngine target, WorkerActionId ActionId, PackageComponent component)
        {
            if (OnAfterGenerate_ExecuteComponent != null)
                OnAfterGenerate_ExecuteComponent(target, ActionId, component);
        }
        
        /// <summary>
        /// Appelé après que le Worker ne génère les actions de configuration d'un package devant se produire après
        /// la génération des actions des composants
        /// </summary>
        /// <param name="target">Engine de destination</param>
        /// <param name="ActionId">Id de l'action</param>
        public delegate void AfterGenerate_ExecuteInstallation_AfterComponents_Handler(DreamWorkerEngine target, WorkerActionId ActionId);

        /// <summary>
        /// Appelé après que le Worker ne génère les actions de configuration d'un package devant se produire après
        /// la génération des actions des composants
        /// </summary>
        public event AfterGenerate_ExecuteInstallation_AfterComponents_Handler OnAfterGenerate_ExecuteInstallation_AfterComponents;

        /// <summary>
        /// Provoque l'évènement OnAfterGenerate_ExecuteInstallation_AfterComponents
        /// </summary>
        /// <param name="target"></param>
        /// <param name="ActionId"></param>
        protected virtual void AfterGenerate_ExecuteInstallation_AfterComponents(DreamWorkerEngine target, WorkerActionId ActionId)
        {
            if (OnAfterGenerate_ExecuteInstallation_AfterComponents != null)
                OnAfterGenerate_ExecuteInstallation_AfterComponents(target, ActionId);
        }

        /// <summary>
        /// Appelé après que le Worker ne génère les actions de configuration d'un package devant se produire avant
        /// la génération des actions des composants
        /// </summary>
        /// <param name="target">Engine de destination</param>
        /// <param name="ActionId">Id de l'action</param>
        public delegate void AfterGenerate_ExecuteInstallation_BeforeComponents_Handler(DreamWorkerEngine target, WorkerActionId ActionId);

        /// <summary>
        /// Appelé après que le Worker ne génère les actions de configuration d'un package devant se produire avant
        /// la génération des actions des composants
        /// </summary>
        public event AfterGenerate_ExecuteInstallation_BeforeComponents_Handler OnAfterGenerate_ExecuteInstallation_BeforeComponents;

        /// <summary>
        /// Provoque l'évènement OnAfterGenerate_ExecuteInstallation_BeforeComponents
        /// </summary>
        /// <param name="target"></param>
        /// <param name="ActionId"></param>
        protected virtual void AfterGenerate_ExecuteInstallation_BeforeComponents(DreamWorkerEngine target, WorkerActionId ActionId)
        {
            if (OnAfterGenerate_ExecuteInstallation_BeforeComponents != null)
                OnAfterGenerate_ExecuteInstallation_BeforeComponents(target, ActionId);
        }
        
        /// <summary>
        /// Appelé après que le Worker ne génère les actions de RollBack
        /// </summary>
        /// <param name="target">Engine de destination</param>
        public delegate void AfterGenerate_RollBack_Handler(DreamWorkerEngine target);

        /// <summary>
        /// Appelé après que le Worker ne génère les actions de RollBack
        /// </summary>
        public event AfterGenerate_RollBack_Handler OnAfterGenerate_RollBack;

        /// <summary>
        /// Provoque l'évènement OnAfterGenerate_RollBack
        /// </summary>
        /// <param name="target"></param>
        protected virtual void AfterGenerate_RollBack(DreamWorkerEngine target)
        {
            if (OnAfterGenerate_RollBack != null)
                OnAfterGenerate_RollBack(target);
        }

        /// <summary>
        /// Appelé avant que le Worker ne génère les actions pour un composant
        /// </summary>
        /// <param name="target">Engine de destination</param>
        /// <param name="ActionId">Id de l'action</param>
        /// <param name="component">Composant actuel</param>
        public delegate void BeforeGenerate_ExecuteComponent_Handler(DreamWorkerEngine target, WorkerActionId ActionId, PackageComponent component);

        /// <summary>
        /// Appelé avant que le Worker ne génère les actions pour un composant
        /// </summary>
        public event BeforeGenerate_ExecuteComponent_Handler OnBeforeGenerate_ExecuteComponent;

        /// <summary>
        /// Provoque l'évènement OnBeforeGenerate_ExecuteComponent
        /// </summary>
        /// <param name="target"></param>
        /// <param name="ActionId"></param>
        /// <param name="component"></param>
        protected virtual void BeforeGenerate_ExecuteComponent(DreamWorkerEngine target, WorkerActionId ActionId, PackageComponent component)
        {
            if(OnBeforeGenerate_ExecuteComponent != null)
                OnBeforeGenerate_ExecuteComponent(target, ActionId, component);
        }

        /// <summary>
        /// Appelé avant que le Worker ne génère les actions de configuration d'un package devant se produire après
        /// la génération des actions des composants
        /// </summary>
        /// <param name="target">Engine de destination</param>
        /// <param name="ActionId">Id de l'action</param>
        public delegate void BeforeGenerate_ExecuteInstallation_AfterComponents_Handler(DreamWorkerEngine target, WorkerActionId ActionId);

        /// <summary>
        /// Appelé avant que le Worker ne génère les actions de configuration d'un package devant se produire après
        /// la génération des actions des composants
        /// </summary>
        public event BeforeGenerate_ExecuteInstallation_AfterComponents_Handler OnBeforeGenerate_ExecuteInstallation_AfterComponents;

        /// <summary>
        /// Provoque l'évènement OnBeforeGenerate_ExecuteInstallation_AfterComponents
        /// </summary>
        /// <param name="target"></param>
        /// <param name="ActionId"></param>
        protected virtual void BeforeGenerate_ExecuteInstallation_AfterComponents(DreamWorkerEngine target, WorkerActionId ActionId)
        {
            if(OnBeforeGenerate_ExecuteInstallation_AfterComponents != null)
                OnBeforeGenerate_ExecuteInstallation_AfterComponents(target, ActionId);
        }

        /// <summary>
        /// Appelé avant que le Worker ne génère les actions de configuration d'un package devant se produire avant
        /// la génération des actions des composants
        /// </summary>
        /// <param name="target">Engine de destination</param>
        /// <param name="ActionId">Id de l'action</param>
        public delegate void BeforeGenerate_ExecuteInstallation_BeforeComponents_Handler(DreamWorkerEngine target, WorkerActionId ActionId);

        /// <summary>
        /// Appelé avant que le Worker ne génère les actions de configuration d'un package devant se produire avant
        /// la génération des actions des composants
        /// </summary>
        public event BeforeGenerate_ExecuteInstallation_BeforeComponents_Handler OnBeforeGenerate_ExecuteInstallation_BeforeComponents;

        /// <summary>
        /// Provoque l'évènement OnBeforeGenerate_ExecuteInstallation_BeforeComponents
        /// </summary>
        /// <param name="target"></param>
        /// <param name="ActionId"></param>
        protected virtual void BeforeGenerate_ExecuteInstallation_BeforeComponents(DreamWorkerEngine target, WorkerActionId ActionId)
        {
            if(OnBeforeGenerate_ExecuteInstallation_BeforeComponents != null)
                OnBeforeGenerate_ExecuteInstallation_BeforeComponents(target, ActionId);
        }
        
        /// <summary>
        /// Appelé avant que le Worker ne génère les actions de RollBack
        /// </summary>
        /// <param name="target">Engine de destination</param>
        public delegate void BeforeGenerate_RollBack_Handler(DreamWorkerEngine target);

        /// <summary>
        /// Appelé avant que le Worker ne génère les actions de RollBack
        /// </summary>
        public event BeforeGenerate_RollBack_Handler OnBeforeGenerate_RollBack;

        /// <summary>
        /// Provoque l'évènement OnBeforeGenerate_RollBack
        /// </summary>
        /// <param name="target"></param>
        protected virtual void BeforeGenerate_RollBack(DreamWorkerEngine target)
        {
            if (OnBeforeGenerate_RollBack != null)
                OnBeforeGenerate_RollBack(target);
        }

        /// <summary>
        /// Appelé avant que l'installeur ne crée un fichier
        /// </summary>
        /// <param name="file_info">Informations relatives au fichier</param>
        /// <param name="file_name">Nom du fichier</param>
        public delegate void IOWorker_CreateFile_Handler(FileInfo file_info, ref string file_name);
        
        /// <summary>
        /// Evènement utilisé pour l'appel à IOWorker_CreateFile
        /// </summary>
        public event IOWorker_CreateFile_Handler OnIOWorker_CreateFile;

        /// <summary>
        /// Provoque l'évènement IOWorker_CreateFile
        /// </summary>
        /// <param name="file_info"></param>
        /// <param name="file_name"></param>
        protected virtual void IOWorker_CreateFile(FileInfo file_info, ref string file_name)
        {
            if(OnIOWorker_CreateFile != null)
                OnIOWorker_CreateFile(file_info, ref file_name);
        }

        /// <summary>
        /// Appelé après que l'installeur ai crée un fichier
        /// </summary>
        public event IOWorker_CreateFile_Handler OnIOWorker_CreateFile_Done;

        /// <summary>
        /// Provoque l'évènement OnIOWorker_CreateFile_Done
        /// </summary>
        /// <param name="file_info"></param>
        /// <param name="file_name"></param>
        protected virtual void IOWorker_CreateFile_Done(FileInfo file_info, ref string file_name)
        {
            if(OnIOWorker_CreateFile_Done != null)
                OnIOWorker_CreateFile_Done(file_info, ref file_name);
        }

        /// <summary>
        /// Appelé lors d'une action sur un fichier
        /// </summary>
        /// <param name="file_info">Fichier concerné</param>
        public delegate void IOWorker_ModifyActionHandler(FileInfo file_info);

        /// <summary>
        /// Appelé avant que l'installeur ne supprime un fichier
        /// </summary>
        public event IOWorker_ModifyActionHandler OnIOWorker_DeleteFile;
        
        /// <summary>
        /// Provoque l'évènement OnIOWorker_DeleteFile
        /// </summary>
        /// <param name="file_info"></param>
        protected virtual void IOWorker_DeleteFile(FileInfo file_info)
        {
            if (OnIOWorker_DeleteFile != null)
                OnIOWorker_DeleteFile(file_info);
        }

        /// <summary>
        /// Appelé après que l'installeur ai supprimé un fichier
        /// </summary>
        public event IOWorker_ModifyActionHandler OnIOWorker_DeleteFile_Done;
        
        /// <summary>
        /// Provoque l'évènement OnIOWorker_DeleteFile_Done
        /// </summary>
        /// <param name="file_info"></param>
        protected virtual void IOWorker_DeleteFile_Done(FileInfo file_info)
        {
            if (OnIOWorker_DeleteFile_Done != null)
                OnIOWorker_DeleteFile_Done(file_info);
        }

        /// <summary>
        /// Appelé avant que l'installeur ne désinstalle un fichier
        /// </summary>
        public event IOWorker_ModifyActionHandler OnIOWorker_UninstallFile;
        
        /// <summary>
        /// Provoque l'évènement OnIOWorker_UninstallFile
        /// </summary>
        /// <param name="file_info"></param>
        protected virtual void IOWorker_UninstallFile(FileInfo file_info)
        {
            if (OnIOWorker_UninstallFile != null)
                OnIOWorker_UninstallFile(file_info);
        }
        
        /// <summary>
        /// Evènement utilisé pour l'appel à IOWorker_UninstallFile_Done
        /// </summary>
        public event IOWorker_ModifyActionHandler OnIOWorker_UninstallFile_Done;

        /// <summary>
        /// Appelé après que l'installeur ai désinstallé un fichier
        /// </summary>
        /// <param name="file_info"></param>
        protected virtual void IOWorker_UninstallFile_Done(FileInfo file_info)
        {
            if (OnIOWorker_UninstallFile_Done != null)
                OnIOWorker_UninstallFile_Done(file_info);
        }

        /// <summary>
        /// Appelé avant que l'installeur ne restaure un fichier
        /// </summary>
        public event IOWorker_ModifyActionHandler OnRestoreFileRollBack;
        
        /// <summary>
        /// Provoque l'évènement OnRestoreFileRollBack
        /// </summary>
        /// <param name="file_info"></param>
        protected virtual void RestoreFileRollBack(FileInfo file_info)
        {
            if (OnRestoreFileRollBack != null)
                OnRestoreFileRollBack(file_info);
        }

        /// <summary>
        /// Evènement utilisé pour l'appel à RestoreFileRollBack_Done
        /// </summary>
        public event IOWorker_ModifyActionHandler OnRestoreFileRollBack_Done;

        /// <summary>
        /// Appelé après que l'installeur ai restauré un fichier
        /// </summary>
        /// <param name="file_info"></param>
        protected virtual void RestoreFileRollBack_Done(FileInfo file_info)
        {
            if (OnRestoreFileRollBack_Done != null)
                OnRestoreFileRollBack_Done(file_info);
        }

        /// <summary>
        /// Appelé lorsque le FileWorker obtient le dossier de destination d'un fichier
        /// </summary>
        /// <param name="target_path">chemin de destination du fichier, pouvant être modifié</param>
        /// <remarks>Si target_path est modifié, le dossier de destination doit exister sinon une erreur sera crée</remarks>
        public delegate void Utils_GetFileTargetPath_Handler(ref string target_path);

        /// <summary>
        /// Appelé lorsque le FileWorker obtient le dossier de destination d'un fichier
        /// </summary>
        public event Utils_GetFileTargetPath_Handler OnUtils_GetFileTargetPath;
        
        /// <summary>
        /// Provoque l'évènement OnUtils_GetFileTargetPath 
        /// </summary>
        /// <param name="target_path"></param>
        protected virtual void Utils_GetFileTargetPath(ref string target_path)
        {
            if (OnUtils_GetFileTargetPath != null)
                OnUtils_GetFileTargetPath(ref target_path);
        }
    }
}
